package com.suda.controller;

import com.suda.pojo.Admin;
import com.suda.pojo.Order;
import com.suda.service.AdminService;
import com.suda.service.OrderService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.security.auth.Subject;
import javax.servlet.http.HttpSession;

@RestController
@CrossOrigin
public class LoginController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result login2(@RequestBody Admin admin){
        System.out.println(admin.getPassword()+"   "+admin.getUsername());
        Admin admin1 = adminService.findById(admin.getUsername());
        System.out.println(admin1);

        if(admin1!=null&&admin1.getPassword().equals(admin.getPassword()))
            return new Result(true, StatusCode.OK,"登录成功");
        else
            return new Result(false, StatusCode.ERROR,"登录失败");
    }

    @PostMapping("/register")
    public Result add(@RequestBody Admin admin){
        adminService.add(admin);
        return new Result(true, StatusCode.OK,"注册成功");
    }
}
